/**
 *
 */
package com.ybkj.daijia.server.service.impl;

import com.ybkj.daijia.common.Pager;
import com.ybkj.daijia.page.Page;
import com.ybkj.daijia.page.Pageable;
import com.ybkj.daijia.page.impl.PageImpl;
import com.ybkj.daijia.page.impl.PageRequest;
import com.ybkj.daijia.server.mapper.FeedbackMapper;
import com.ybkj.daijia.server.model.Feedback;
import com.ybkj.daijia.server.service.FeedbackService;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author Shine
 *
 */
@Service
public class DefaultFeedbackService implements FeedbackService {

    @Autowired
    private FeedbackMapper feedbackMapper;


    /* (non-Javadoc)
     * @see com.ybkj.shop.service.AdminService#queryAll()
     */
    public Page<Feedback> queryAll() {

        Pageable pageable = new PageRequest(Pager.getPage(), Pager.getLimit());

        List<Feedback> content = feedbackMapper.selectByPage(Pager.getOffset(), Pager.getLimit());
        int total = feedbackMapper.countAll();

        return new PageImpl<Feedback>(content, pageable, total);
    }

    @Transactional(rollbackFor = Exception.class)
    public Feedback insertRecord(Feedback feedback) {

        feedbackMapper.insertRecord(feedback);

        return feedback;

    }

    public Feedback findOne(Long id) {

        return feedbackMapper.selectByPrimaryKey(id);
    }


    @Transactional(rollbackFor = Exception.class)
    public void delete(Feedback feedback) {

        feedbackMapper.deleteByPrimaryKey(feedback.getId());

    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public int updateByPrimaryKey(Feedback record) {

        return feedbackMapper.updateByPrimaryKey(record);
    }

}